<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>LibTools: H:/project/LibTools/src/algorithm/CSafeSList.h 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">LibTools
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.16 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',false,false,'search.php','搜索');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_68267d1309a1af8e8297ef4c3efbcdba.html">src</a></li><li class="navelem"><a class="el" href="dir_fbc178c12bd249518b3c0868875b8083.html">algorithm</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">CSafeSList.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="_c_safe_s_list_8h.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#ifndef __SAFESLIST_H__</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#define __SAFESLIST_H__</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &quot;../thread/Mutex.h&quot;</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &lt;list&gt;</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160; </div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<a class="code" href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;</div>
<div class="line"><a name="l00012"></a><span class="lineno"><a class="line" href="class_c_safe_s_list.html">   12</a></span>&#160;<span class="keyword">class </span><a class="code" href="class_c_safe_s_list.html">CSafeSList</a></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;{</div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00020"></a><span class="lineno"><a class="line" href="class_c_safe_s_list.html#ab6d59be07d96023caf676116c6ace138">   20</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="class_c_safe_s_list.html#ab6d59be07d96023caf676116c6ace138">Empty</a>()</div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;    {</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;        <a class="code" href="class_c_lock_gurad.html">CLockGurad</a> lock(&amp;<a class="code" href="class_c_safe_s_list.html#ab22ac904b04b864f9a34001b79b44a80">_mutexList</a>);</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">_list</a>.<a class="code" href="class_s_list.html#a3b48968b04b9229ed20c65280684d054">empty</a>();</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;    }</div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160; </div>
<div class="line"><a name="l00030"></a><span class="lineno"><a class="line" href="class_c_safe_s_list.html#affd47329140b999b7bd07fbb8d7167d1">   30</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="class_c_safe_s_list.html#affd47329140b999b7bd07fbb8d7167d1">InsertBack</a>(<span class="keyword">const</span> T&amp; value)</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;    {</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        <a class="code" href="class_c_lock_gurad.html">CLockGurad</a> lock(&amp;<a class="code" href="class_c_safe_s_list.html#ab22ac904b04b864f9a34001b79b44a80">_mutexList</a>);</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;         <a class="code" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">_list</a>.<a class="code" href="class_s_list.html#ad4c16ab36ff96807d563b02cc48b390c">push_back</a>(value);</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;    }</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160; </div>
<div class="line"><a name="l00041"></a><span class="lineno"><a class="line" href="class_c_safe_s_list.html#a6bec05153ef6502e832e561db26ad5eb">   41</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="class_c_safe_s_list.html#a6bec05153ef6502e832e561db26ad5eb">PopFront</a>(T&amp; value)</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    {</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        <a class="code" href="class_c_lock_gurad.html">CLockGurad</a> lock(&amp;<a class="code" href="class_c_safe_s_list.html#ab22ac904b04b864f9a34001b79b44a80">_mutexList</a>);</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">_list</a>.<a class="code" href="class_s_list.html#a3b48968b04b9229ed20c65280684d054">empty</a>()) <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        value = <a class="code" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">_list</a>.<a class="code" href="class_s_list.html#a043d551be57af2dc9b8eb1a974bad632">front</a>();</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;         <a class="code" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">_list</a>.<a class="code" href="class_s_list.html#ae3602c607764f52f30f7d864b6c76d3d">pop_front</a>();</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    }</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160; </div>
<div class="line"><a name="l00054"></a><span class="lineno"><a class="line" href="class_c_safe_s_list.html#a3c301d884f8f9f5b92b78711ad945613">   54</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="class_c_safe_s_list.html#a3c301d884f8f9f5b92b78711ad945613">Front</a>(T&amp; value)</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    {</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;        <a class="code" href="class_c_lock_gurad.html">CLockGurad</a> lock(&amp;<a class="code" href="class_c_safe_s_list.html#ab22ac904b04b864f9a34001b79b44a80">_mutexList</a>);</div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        <span class="keywordflow">if</span> (<a class="code" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">_list</a>.<a class="code" href="class_s_list.html#a3b48968b04b9229ed20c65280684d054">empty</a>()) <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        value = <a class="code" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">_list</a>.<a class="code" href="class_s_list.html#a043d551be57af2dc9b8eb1a974bad632">front</a>();</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    }</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160; </div>
<div class="line"><a name="l00066"></a><span class="lineno"><a class="line" href="class_c_safe_s_list.html#a5248872778d230ffb571d16b901c0149">   66</a></span>&#160;    <a class="code" href="tools_8h.html#a36cb3b01d81ffd844bbbfb54003e06ec">UINT</a> <a class="code" href="class_c_safe_s_list.html#a5248872778d230ffb571d16b901c0149">Size</a>()</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    {</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;        <span class="keywordflow">return</span> _size;</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    }</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00071"></a><span class="lineno"><a class="line" href="class_c_safe_s_list.html#ab22ac904b04b864f9a34001b79b44a80">   71</a></span>&#160;    <a class="code" href="class_c_mutex.html">CMutex</a> <a class="code" href="class_c_safe_s_list.html#ab22ac904b04b864f9a34001b79b44a80">_mutexList</a>;</div>
<div class="line"><a name="l00072"></a><span class="lineno"><a class="line" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">   72</a></span>&#160;    <a class="code" href="class_s_list.html">SList&lt;T&gt;</a> <a class="code" href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">_list</a>;</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;};</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160; </div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;<a class="code" href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160; </div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;<span class="preprocessor">#endif // endif __SAFESLIST_H__</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aclass_s_list_html"><div class="ttname"><a href="class_s_list.html">SList&lt; T &gt;</a></div></div>
<div class="ttc" id="aclass_c_safe_s_list_html_ab6d59be07d96023caf676116c6ace138"><div class="ttname"><a href="class_c_safe_s_list.html#ab6d59be07d96023caf676116c6ace138">CSafeSList::Empty</a></div><div class="ttdeci">bool Empty()</div><div class="ttdoc">判断链表中是否为空</div><div class="ttdef"><b>Definition:</b> <a href="_c_safe_s_list_8h_source.html#l00020">CSafeSList.h:20</a></div></div>
<div class="ttc" id="aclass_s_list_html_a3b48968b04b9229ed20c65280684d054"><div class="ttname"><a href="class_s_list.html#a3b48968b04b9229ed20c65280684d054">SList::empty</a></div><div class="ttdeci">bool empty() const</div><div class="ttdoc">判断链表是否为空</div><div class="ttdef"><b>Definition:</b> <a href="_s_list_8h_source.html#l00418">SList.h:418</a></div></div>
<div class="ttc" id="aclass_c_mutex_html"><div class="ttname"><a href="class_c_mutex.html">CMutex</a></div><div class="ttdoc">常规锁</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8h_source.html#l00025">Mutex.h:25</a></div></div>
<div class="ttc" id="aclass_c_safe_s_list_html"><div class="ttname"><a href="class_c_safe_s_list.html">CSafeSList</a></div><div class="ttdoc">线程安全操作链表类</div><div class="ttdef"><b>Definition:</b> <a href="_c_safe_s_list_8h_source.html#l00012">CSafeSList.h:12</a></div></div>
<div class="ttc" id="atools_8h_html_a201ce692c9dca6599e5c12d00167419b"><div class="ttname"><a href="tools_8h.html#a201ce692c9dca6599e5c12d00167419b">DEF_BEG_LIBTOOLS</a></div><div class="ttdeci">#define DEF_BEG_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00036">tools.h:36</a></div></div>
<div class="ttc" id="aclass_c_lock_gurad_html"><div class="ttname"><a href="class_c_lock_gurad.html">CLockGurad</a></div><div class="ttdoc">常规锁包装器</div><div class="ttdef"><b>Definition:</b> <a href="_mutex_8h_source.html#l00041">Mutex.h:41</a></div></div>
<div class="ttc" id="aclass_c_safe_s_list_html_ab9e942724c0cce2b04831249fa1b295b"><div class="ttname"><a href="class_c_safe_s_list.html#ab9e942724c0cce2b04831249fa1b295b">CSafeSList::_list</a></div><div class="ttdeci">SList&lt; T &gt; _list</div><div class="ttdef"><b>Definition:</b> <a href="_c_safe_s_list_8h_source.html#l00072">CSafeSList.h:72</a></div></div>
<div class="ttc" id="atools_8h_html_ac909db71799bb22cb7d636a34cd785e4"><div class="ttname"><a href="tools_8h.html#ac909db71799bb22cb7d636a34cd785e4">DEF_END_LIBTOOLS</a></div><div class="ttdeci">#define DEF_END_LIBTOOLS</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00038">tools.h:38</a></div></div>
<div class="ttc" id="aclass_s_list_html_a043d551be57af2dc9b8eb1a974bad632"><div class="ttname"><a href="class_s_list.html#a043d551be57af2dc9b8eb1a974bad632">SList::front</a></div><div class="ttdeci">const_reference front() const</div><div class="ttdef"><b>Definition:</b> <a href="_s_list_8h_source.html#l00410">SList.h:410</a></div></div>
<div class="ttc" id="aclass_c_safe_s_list_html_a5248872778d230ffb571d16b901c0149"><div class="ttname"><a href="class_c_safe_s_list.html#a5248872778d230ffb571d16b901c0149">CSafeSList::Size</a></div><div class="ttdeci">UINT Size()</div><div class="ttdoc">返回链表的大小</div><div class="ttdef"><b>Definition:</b> <a href="_c_safe_s_list_8h_source.html#l00066">CSafeSList.h:66</a></div></div>
<div class="ttc" id="atools_8h_html_a36cb3b01d81ffd844bbbfb54003e06ec"><div class="ttname"><a href="tools_8h.html#a36cb3b01d81ffd844bbbfb54003e06ec">UINT</a></div><div class="ttdeci">unsigned int UINT</div><div class="ttdef"><b>Definition:</b> <a href="tools_8h_source.html#l00139">tools.h:139</a></div></div>
<div class="ttc" id="aclass_c_safe_s_list_html_affd47329140b999b7bd07fbb8d7167d1"><div class="ttname"><a href="class_c_safe_s_list.html#affd47329140b999b7bd07fbb8d7167d1">CSafeSList::InsertBack</a></div><div class="ttdeci">void InsertBack(const T &amp;value)</div><div class="ttdoc">向链表尾部中插入一个数据</div><div class="ttdef"><b>Definition:</b> <a href="_c_safe_s_list_8h_source.html#l00030">CSafeSList.h:30</a></div></div>
<div class="ttc" id="aclass_c_safe_s_list_html_ab22ac904b04b864f9a34001b79b44a80"><div class="ttname"><a href="class_c_safe_s_list.html#ab22ac904b04b864f9a34001b79b44a80">CSafeSList::_mutexList</a></div><div class="ttdeci">CMutex _mutexList</div><div class="ttdef"><b>Definition:</b> <a href="_c_safe_s_list_8h_source.html#l00071">CSafeSList.h:71</a></div></div>
<div class="ttc" id="aclass_s_list_html_ae3602c607764f52f30f7d864b6c76d3d"><div class="ttname"><a href="class_s_list.html#ae3602c607764f52f30f7d864b6c76d3d">SList::pop_front</a></div><div class="ttdeci">void pop_front()</div><div class="ttdoc">删除第一个元素</div><div class="ttdef"><b>Definition:</b> <a href="_s_list_8h_source.html#l00463">SList.h:463</a></div></div>
<div class="ttc" id="aclass_s_list_html_ad4c16ab36ff96807d563b02cc48b390c"><div class="ttname"><a href="class_s_list.html#ad4c16ab36ff96807d563b02cc48b390c">SList::push_back</a></div><div class="ttdeci">void push_back(const_reference value)</div><div class="ttdef"><b>Definition:</b> <a href="_s_list_8h_source.html#l00456">SList.h:456</a></div></div>
<div class="ttc" id="aclass_c_safe_s_list_html_a6bec05153ef6502e832e561db26ad5eb"><div class="ttname"><a href="class_c_safe_s_list.html#a6bec05153ef6502e832e561db26ad5eb">CSafeSList::PopFront</a></div><div class="ttdeci">bool PopFront(T &amp;value)</div><div class="ttdoc">删除链表头部数据，并返回相应的值</div><div class="ttdef"><b>Definition:</b> <a href="_c_safe_s_list_8h_source.html#l00041">CSafeSList.h:41</a></div></div>
<div class="ttc" id="aclass_c_safe_s_list_html_a3c301d884f8f9f5b92b78711ad945613"><div class="ttname"><a href="class_c_safe_s_list.html#a3c301d884f8f9f5b92b78711ad945613">CSafeSList::Front</a></div><div class="ttdeci">bool Front(T &amp;value)</div><div class="ttdoc">返回链表的头部数据，并删除</div><div class="ttdef"><b>Definition:</b> <a href="_c_safe_s_list_8h_source.html#l00054">CSafeSList.h:54</a></div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.16
</small></address>
</body>
</html>
